package com.leetcode.algorithm.y22.m07.w4;

/**
 * 860. 柠檬水找零
 * 
 * https://leetcode.cn/problems/lemonade-change/
 * 
 * @author jie.deng
 *
 */
class Question0860Solution01 {

	public boolean lemonadeChange(int[] bills) {
		int[] cntArr = new int[2];
		for (int i = 0; i < bills.length; i++) {
			int bill = bills[i];
			if (bill == 5) {
				cntArr[0]++;
			} else if (bill == 10) {
				if (cntArr[0] == 0) {
					return false;
				} else {
					cntArr[1]++;
					cntArr[0]--;
				}
			} else if (bill == 20) {
				if (cntArr[1] == 0) {
					if (cntArr[0] < 3) {
						return false;
					} else {
						cntArr[0] -= 3;
					}
				} else {
					cntArr[1]--;
					if (cntArr[0] == 0) {
						return false;
					} else {
						cntArr[0]--;
					}
				}
			}
		}
		return true;
	}

}